package gervosou;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.DropMode;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.GregorianCalendar;
import javax.swing.JSeparator;
import javax.swing.JList;
import javax.swing.JScrollPane;

public class VueNouvMandataire extends Vue {

	/**
	 * 
	 */
	//private static final long serialVersionUID = 5069349224425178639L;
	private JPanel contentPane;
	private JTextField textFieldNom;
	private JTextField textFieldPrenom;
	
	// pour que les boutons soient des attributs, il faut faire "convert local to field"
	private JButton btnEnregistrer;
	private JButton btnAnnuler;

	// a ajouter car la vue est observatrice d'un client
		private Mandataire _mand ;
		private JTextField textFieldDatedeNaissance;
		private JList listSoc;
	
	/**
	 * Create the frame.
	 */
	public VueNouvMandataire(Controleur controleur) {
		super (controleur);
		setTitle("Enregistrement d'une nouvelle societe");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 429, 499);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(66, 221, 304, 155);
		contentPane.add(scrollPane);
		
		
		JLabel lblNom = new JLabel("Nom");
		lblNom.setBounds(66, 37, 48, 16);
		contentPane.add(lblNom);
		
		listSoc = new JList();
		scrollPane.setViewportView(listSoc);
		listSoc.setListData(getControleur().getSociete().keySet().toArray());
		
		textFieldNom = new JTextField();
		textFieldNom.setBounds(162, 32, 190, 28);
		textFieldNom.setBackground(new Color(255, 255, 255));
		contentPane.add(textFieldNom);
		textFieldNom.setColumns(10);
		
		btnEnregistrer = new JButton("Enregistrer");
		btnEnregistrer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nomM = textFieldNom.getText();
				String prenomM = textFieldPrenom.getText();
				String dn = textFieldDatedeNaissance.getText();
				String Soc = listSoc.getSelectedValue().toString();
				//etControleur().NouvMandataire(nomM, prenomM, dn, Soc);
			}
		});
		btnEnregistrer.setBounds(245, 394, 117, 52);
		contentPane.add(btnEnregistrer);
		
		btnAnnuler = new JButton("Annuler");
		btnAnnuler.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getControleur().fermerVue(VueNouvMandataire.this);
			}
		});
		btnAnnuler.setBounds(116, 406, 117, 29);
		contentPane.add(btnAnnuler);
		
		JLabel lblAdresse = new JLabel("Prenom");
		lblAdresse.setBounds(53, 77, 61, 16);
		contentPane.add(lblAdresse);
		
		textFieldPrenom = new JTextField();
		textFieldPrenom.setColumns(10);
		textFieldPrenom.setBounds(162, 72, 190, 28);
		contentPane.add(textFieldPrenom);
		
		JLabel lblInfosSoc = new JLabel("Societe liée:");
		lblInfosSoc.setBounds(7, 194, 97, 15);
		contentPane.add(lblInfosSoc);
		
		JLabel lblInfosDeBase = new JLabel("Infos de base:");
		lblInfosDeBase.setBounds(7, 12, 97, 15);
		contentPane.add(lblInfosDeBase);
		
		textFieldDatedeNaissance = new JTextField();
		textFieldDatedeNaissance.setColumns(10);
		textFieldDatedeNaissance.setBounds(162, 112, 190, 28);
		contentPane.add(textFieldDatedeNaissance);
		


		
		JLabel lblDateDeNaissance = new JLabel("Date de naissance");
		lblDateDeNaissance.setBounds(12, 118, 132, 16);
		contentPane.add(lblDateDeNaissance);
	}
	
	public void setEtat (int etat){
		switch (etat) {
		case initiale: {
			btnEnregistrer.setEnabled(true);
			btnAnnuler.setEnabled(true);
			break;
			}
		}
	}
}
